package tests;
import java.util.Vector;

import junit.framework.TestCase;
import objects.User;
import DB.DB;
import Domain.forumManager.ForumController;

public class ForumControllerTest extends TestCase {
DB d=new DB();
ForumController f=new ForumController(d);

	public void testForumController() {
		assertNotNull(f);
	}

	public void testAddFreind() {
		User a=new User("Asaf");
		User b=new User("Dudi");
		f.addUser(a);
		f.addUser(b);
		f.addFreind("Asaf", "Dudi");
		assertTrue(b.getFrindList().contains(a));
		
	}

	public void testRemoveFriend() {
		User a=new User("Asaf");
		User b=new User("Dudi");
		f.addUser(a);
		f.addUser(b);
		f.addFreind("Asaf", "Dudi");
		f.removeFriend("Asaf", "Dudi");
		assertFalse(a.getFrindList().contains(b));
	}

	public void testCreateUser() {
		f.createUser("Asaf");
		assertEquals(f.getUserByName("Asaf").get_nameOfUser(), "Asaf");
	}

	public void testRemoveUserString() {
		f.createUser("Asaf");
		f.removeUser("Asaf");
		assertNull(f.getUserByName("Asaf"));
	}

	public void testRemoveUserUser() {
		User a=new User("Asaf");
		f.addUser(a);
		f.removeUser(a);
		assertNull(f.getUserByName("Asaf"));
	}

	public void testAddForum() {
		User a=new User("Asaf");
		f.addUser(a);
		
		assertEquals(f.addForum("Manassen", "Asaf"), -2);
		a.setAsManager();
		assertEquals(f.addForum("Manassen", "Asaf"), 1);
		
	}


	public void testAddThread() {
		User a=new User("Asaf");
		f.addUser(a);
		a.setAsManager();
		f.addForum("Manassen", "Asaf");
		f.addThread("Manassen", "Asaf", "mnsn");
		
		a.setAsManager();
		assertEquals(f.getThreads("Manassen").get(0).get_nameOfThread(),"mnsn");
		
	}

	public void testAddMessage() {
		User a=new User("Asaf");
		a.setAsManager();
		f.addUser(a);
		f.addForum("Manassen", "Asaf");
		f.addThread("Manassen", "Asaf", "mnsn");
		f.addMessage("Manassen", "Asaf", "mnsn", "hello");
		assertEquals(f.getMessages("Manassen", "mnsn").get(0).getMessage(), "hello");
	}
	public void testgetAllUsers()
	{
		User a=new User("Asaf");
		User b=new User("Dudi");
		
		f.addUser(a);
		f.addUser(b);
		Vector <User> ans=f.getAllUsers();
		assertTrue(ans.contains(a));
		assertTrue(ans.contains(b));
		Vector ans1=f.getAllUsersAsString();
		assertEquals(ans1.get(1), "Asaf");
		assertEquals(ans1.get(2), "Dudi");
	}

}
